/*
 * mainPlugin.cpp
 *
 *  Created on: 2017年5月30日
 *      Author: orange
 */

#include "mainPlugin.h"

#include <utility>

#include "public/event/OnDisableJuzEvent.h"
#include "public/event/OnEnableJuzEvent.h"
#include "public/event/ThreadJuzEvent.h"
#include "public/event/SendSocketJuzEvent.h"
#include "public/event/ClientQuitJuzEvent.h"
#include "public/event/AskEncryptionJuzEvent.h"
#include "public/event/TaskJuzEvent.h"
#include "public/event/SocketInfoJuzEvent.h"
#include "public/event/OnCommandJuzEvent.h"

#include <unistd.h>
#include <string.h>
#include <sstream>

extern "C"
{
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
}

using namespace std;

#define PRO_THREAD   40
 mainPlugin *mainPlugin::mMainPlguin = NULL;

 static lua_State *L_ReadUserPass = NULL;

 mainPlugin* mainPlugin::getInstance() {
 	if(mMainPlguin == NULL)
 	{
 		mMainPlguin = new  mainPlugin();
 	}
 	return mMainPlguin;
 }
mainPlugin::mainPlugin() {

	task_sem = new sem_t;
	sem_init(task_sem, 0, 0);
}

mainPlugin::~mainPlugin() {
	// TODO Auto-generated destructor stub
	OnDisable();
}
void *mainPlugin::WndPro(void* arr)
{
	while(1)
	{
		sem_wait(mainPlugin::getInstance()->task_sem);
		TaskJuzEvent *ev = NULL;
		if(mainPlugin::getInstance()->mTaskList.try_dequeue(ev))
		{
			switch(ev->getWhat())
			{
			case 2://转发事件
			{
				JuzEvent *toEv = (JuzEvent*)ev->getArg1();
				if(toEv != NULL)
				{
					JuzLog::LogA(4,"转发事件:%s",toEv->mEventName);

					mainPlugin::getInstance()->sendEvent(toEv);
					delete toEv;
				}
			}
				break;
			}
			//要删除ｅｖ事件
			delete ev;
		}
	}
}

void mainPlugin::bindFinsh() {
	registeredEvent(OnEnableJuzEvent::mEventName,11);
	registeredEvent(OnDisableJuzEvent::mEventName,11);
	registeredEvent(TaskJuzEvent::mEventName,11);
	registeredEvent(OnCommandJuzEvent::mEventName,1);

	registeredEvent(SocketInfoJuzEvent::mEventName,20);//网络信息
	registeredEvent(ClientQuitJuzEvent::mEventName,20);//客户端退出
}

void mainPlugin::OnDisable() {
	sem_destroy(task_sem);
}


int runMcServer(lua_State *L)
{
    string user = lua_tostring(L,1);
    string pass = lua_tostring(L,2);

    McServer *mc = new McServer(user,pass);
    mainPlugin::mMainPlguin->insertMcServer(user,mc);

    return 0;
}

void mainPlugin::OnEnable() {

	//创建虚拟机
	lua_State *L = luaL_newstate();

    if (L == NULL)
    {
        return ;
    }

    L_ReadUserPass = L;

    //加载基本库
    luaL_openlibs(L);

    /* 注册函数 */
    lua_register(L, "runMcServer", runMcServer);

    //2.加载Lua文件
    int bRet = luaL_loadfile(L,"./userPass.lua");
    if(bRet)
    {
        cout<<"load file error"<<endl;
        return ;
    }
    //3.运行Lua文件
    bRet = lua_pcall(L,0,0,0);
    if(bRet)
    {
        cout<<"pcall error:"<<bRet<<endl;
        const char *pErrorMsg = lua_tostring(L, -1);
        cout << pErrorMsg << endl;
        lua_close(L);

        return ;
    }


	//启动线程
	for(int i = 0 ; i < PRO_THREAD ; i++)
	{
        ThreadJuzEvent threadEpollPro("pro 数据处理线程");
        threadEpollPro.setTask(mainPlugin::WndPro);
        sendEvent(&threadEpollPro); //发送事件出去
	}
}
void mainPlugin::eventListen(JuzEvent* event) {
	string evName = event->mEventName;

	JuzLog::LogA(3,"mainPlugin::eventListen %s",event->mEventName);

	if(evName == OnEnableJuzEvent::mEventName)
	{
		OnEnable();
	}
	else if(evName == OnDisableJuzEvent::mEventName)
	{
		OnDisable();
	}
	else if(evName == TaskJuzEvent::mEventName)
	{
		TaskJuzEvent *mTaskEv = (TaskJuzEvent*)event;
		if(mTaskList.enqueue(mTaskEv))
		{
			sem_post(task_sem); //增加信号量
		}
	}
	else if(evName == SocketInfoJuzEvent::mEventName)
	{
		socketPro((SocketInfoJuzEvent*)event);
	}
	else if(evName == ClientQuitJuzEvent::mEventName)
	{
		//客户端退出
		clientQuit((ClientQuitJuzEvent*)event);

	}
	else if(evName == OnCommandJuzEvent::mEventName)
	{
		OnCommandJuzEvent* ev = (OnCommandJuzEvent*)event;
		int nLen = ev->getLen();
		if(nLen == 3)
		{
			string strCommand = ev->getCommand(0);
			if(strCommand == "reg")
			{
				if(L_ReadUserPass != NULL)
				{
					string user =  ev->getCommand(1);
					string pass =  ev->getCommand(2);

				    lua_getglobal(L_ReadUserPass,"try_save");
				    lua_pushstring(L_ReadUserPass,user.c_str());
				    lua_pushstring(L_ReadUserPass,pass.c_str());
				    lua_pcall(L_ReadUserPass, 2, 0, 0);
				}
			}
		}
	}
}
void mainPlugin::clientQuit(ClientQuitJuzEvent *ev)
{
	//不和你多bb 直接上锁寻找
	int clientFd = ev->getSocketId();
	int nQuitId = ev->getQuitId();//退出码

	JuzLog::LogStr("mainPlugin::clientQuit",4);

	AskEncryptionJuzEvent askEv(clientFd);
	sendEvent(&askEv);

	if(!askEv.isIsYes()) return ; //如果没加密

	JuzLog::LogStr("mainPlugin::clientQuit AskEncryptionJuzEvent yes",4);

	bool isServer = false;
	bool isClient = false;
	McServer *Quitserver = NULL;

	mMcServerLock.readLock();

	mMcServerIterator it;
    for(it = mMcServer.begin();it != mMcServer.end(); ++it)
    {
    	McServer *server = it->second;
    	if(server->getRootFd() == clientFd)
    	{
    		isServer = true;
    	}
    	else
    	{
    		server->mAndroidClientLock.readLock();
    		auto it = server->mAndroidClient.find(clientFd);
    		if(it != server->mAndroidClient.end())
    		{
    			JuzLog::LogStr("mAndroidClient 找到",4);
    			isClient = true; //找到了
    		}
    		server->mAndroidClientLock.unLock();
    	}
    	if(isServer || isClient )
    	{
    		Quitserver = server;
    		break;
    	}
    }

	mMcServerLock.unLock();

	JuzLog::LogStr("clientQuit　退出",4);

	if(isServer) //mc服务器退出了
	{
		Quitserver->setRootFd(-1);
		//可以强制所有 android 下线!

		JuzLog::LogA(4,"server 退出 fd:%d",clientFd);
	}
	else if(isClient)//客户端退出了
	{
		Quitserver->mAndroidClientLock.writeLock();
		auto delIt = Quitserver->mAndroidClient.find(clientFd);
		if(delIt != Quitserver->mAndroidClient.end())
		{
			delete delIt->second;
			Quitserver->mAndroidClient.erase(delIt);

			JuzLog::LogA(4,"android 退出 fd:%d",clientFd);
		}
		Quitserver->mAndroidClientLock.unLock();
	}
}

void mainPlugin::socketPro(SocketInfoJuzEvent *socketInfo)
{
	int nLen = socketInfo->getLen();
	char what = socketInfo->getWhat();
	char type = socketInfo->getType();
	char arg1 = socketInfo->getArg1();
	char arg2 = socketInfo->getArg2();
	char *pData = socketInfo->getData();
	int nDataLen = nLen - SOCKETHEAD;

	JuzLog::LogA(4,"mainPlugin::socketPro:what %d type %d arg1 %d arg2 %d nLen %d",what,type,arg1,arg2,nLen);

	if(what == 0x01 && type == 0x02) //mC服务器登录信息
	{
		mcOnLogin(socketInfo);
	}
	else if(what == 0x01 && type == 0x03) //android 客户端登录
	{
		androidOnLogin(socketInfo);
	}
	else if(what == 0x01 && type == 0x04)//mc服务器返回登录信息
	{
		backAndroidUser(socketInfo);
	}
	else if(what == 0x01 && type == 0x05)
	{
		//android 聊天信息
		androidChat(socketInfo);
	}
	else if(what == 0x01 && type == 0x06)
	{
		//ｍｃ聊天信息
		mcServerChat(socketInfo);
	}
	else if(what == 0x02 && type == 0x01)
	{
		mcSyncPeopleNum(socketInfo);
	}
}
/////////////////////////////////////////////////////////////
McServer* mainPlugin::getMcServer(int nfd)
{
	McServer *mcServer = NULL;
	bool isFind = false;


	mMcServerLock.readLock();
	 for (auto iter = mMcServer.begin(); iter != mMcServer.end(); ++iter)
	 {
		 mcServer = iter->second;
		 if(mcServer->getRootFd() == nfd)
		 {
			 isFind = true;
			 break;
		 }

	 }
	mMcServerLock.unLock();

	if(!isFind)
	{
		mcServer = NULL;
	}

	return mcServer;
}
void mainPlugin::mcSyncPeopleNum(SocketInfoJuzEvent *socketInfo)
{
	//ｍｃ服务器同步人数

	int serverFD = socketInfo->getNfd();
	McServer *mcServer = getMcServer(serverFD);

	if(mcServer != NULL)
	{
		int peoPleNum = socketInfo->getArg1();

		JuzLog::LogA(4,"mainPlugin::mcSyncPeopleNum 在线人数为:%d 服务器账号为:%s",peoPleNum,mcServer->mUser.c_str());
		mcServer->setmNumPeople(peoPleNum);

		mcServer->mAndroidClientLock.readLock();
	    for (auto iter = mcServer->mAndroidClient.begin(); iter != mcServer->mAndroidClient.end(); ++iter)
	    {
	    	int sendFD = iter->first;

	    	char test[3] = "12";
			//发送
			SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
					sendFD, 0x02, 0x01,peoPleNum , 0x00, sizeof(test), (char*)test);

			mainPlugin::getInstance()->sendEvent(sendKey);
	    }
	    mcServer->mAndroidClientLock.unLock();

	}
}


void mainPlugin::mcServerChat(SocketInfoJuzEvent *socketInfo)
{
	int serverFD = socketInfo->getNfd();
	JUZCHATINFO *juchat = (JUZCHATINFO*)socketInfo->getData();
	McServer *mcServer = NULL;
	bool isFind = false;

	JuzLog::LogA(4,"mainPlugin::mcServerChat FD:%d isFind %d",serverFD,isFind);

	mMcServerLock.readLock();
	 for (auto iter = mMcServer.begin(); iter != mMcServer.end(); ++iter)
	 {
		 mcServer = iter->second;
		 if(mcServer->getRootFd() == serverFD)
		 {
			 isFind = true;
			 break;
		 }

	 }
	mMcServerLock.unLock();

	JuzLog::LogA(4,"2222mainPlugin::mcServerChat FD:%d isFind %d",serverFD,isFind);

	if(isFind )
	{
		mcServer->mAndroidClientLock.readLock();
	    for (auto iter = mcServer->mAndroidClient.begin(); iter != mcServer->mAndroidClient.end(); ++iter)
	    {
	    	int sendFD = iter->first;

	    	JuzLog::LogA(4,"mcServerChat聊天　用户名:%s,聊天信息:%s　位置:%s android FD:%d",juchat->user,juchat->chat,juchat->place,sendFD);

			//发送
			SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
					sendFD, 0x01, 0x05, 0x00, 0x00, sizeof(JUZCHATINFO), (char*)juchat);
			sendKey->setPublicEncryption();

			mainPlugin::getInstance()->sendEvent(sendKey);
	    }
	    mcServer->mAndroidClientLock.unLock();
	}

}
void mainPlugin::androidChat(SocketInfoJuzEvent *socketInfo)
{
	int clientFD = socketInfo->getNfd();
	JuzCHATANDROID *juzStruct = (JuzCHATANDROID*)socketInfo->getData();
	//１．先寻找服务器
	string serverUser = juzStruct->serverUser;
	McServer *mcServer = NULL;

	JuzLog::LogStr("android聊天寻找服务器!",4);

	mMcServerLock.readLock();
	auto it = mMcServer.find(serverUser);
	if(it != mMcServer.end())
	{
		mcServer = it->second;
	}
	mMcServerLock.unLock();
	int serverFD = -1;

	if(mcServer != NULL && (serverFD = mcServer->getRootFd()) != -1)
	{
		JuzLog::LogStr("android聊天找到服务器!",4);

		//在线
		mcServer->mAndroidClientLock.readLock();
		auto AndroidFindit = mcServer->mAndroidClient.find(clientFD);
		if(AndroidFindit != mcServer->mAndroidClient.end())
		{
			JUZ_ANDROID_CLIENT *jzAndroid = AndroidFindit->second;
			if(jzAndroid->isLogin) //如果是登录成功状态
			{
				//发送聊天信息
				JUZCHATINFO juz;
				memcpy(juz.chat,juzStruct->chat,sizeof(juzStruct->chat));
				memcpy(juz.user,juzStruct->user,sizeof(juzStruct->user));
				memcpy(juz.place,juzStruct->place,sizeof(juzStruct->place));

				int sendFD = serverFD;

				auto sendPro = [&](int nSendfd){

					JuzLog::LogA(4,"android 发起聊天发给fd:%d 用户名:%s 聊天信息:%s",nSendfd,juz.user,juz.chat);

					//发送
					SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
							nSendfd, 0x01, 0x05, 0x00, 0x00, sizeof(JUZCHATINFO), (char*)&juz);
					sendKey->setPublicEncryption();

					mainPlugin::getInstance()->sendEvent(sendKey);
				};
				sendPro(sendFD);
			    for (auto iter = mcServer->mAndroidClient.begin(); iter != mcServer->mAndroidClient.end(); ++iter)
			    {
			    	int sendFD = iter->first;
			    	sendPro(sendFD);
			    }
			}
		}
		mcServer->mAndroidClientLock.unLock();
	}

	delete[] socketInfo->getData();
}
void mainPlugin::backAndroidUser(SocketInfoJuzEvent *socketInfo)
{
	int nDataLen = socketInfo->getLen() - SOCKETHEAD;
	int nSocketFD = socketInfo->getNfd();
	STRUCT_AskUser *askUser = (STRUCT_AskUser*)socketInfo->getData();
	int sendUserID = askUser->nfd;

	int nResult = -1;

	int nLoginSuccessFD = -1;

	if(askUser->isYes)
	{
		//登录成功
		string serverUser = askUser->ju.serverUser;
		string sendUser = askUser->ju.user;
		string sendPass = askUser->ju.pass;
		McServer *mcServer = NULL;

		JuzLog::LogStr("backAndroidUser 登录成功");
		mMcServerLock.readLock();
		auto it = mMcServer.find(serverUser);
		if(it != mMcServer.end())
		{
			mcServer = it->second;
		}
		mMcServerLock.unLock();

		JuzLog::LogA(4,"android 登录成功:服务器账号:%s 用户名:%s 密码:%s",askUser->ju.serverUser,askUser->ju.user,askUser->ju.pass);

		if(mcServer != NULL && nSocketFD == mcServer->getRootFd())
		{
			JuzLog::LogStr("android 登录成功　准备记录",4);
			mcServer->mAndroidClientLock.writeLock();
		    for (auto iter = mcServer->mAndroidClient.begin(); iter != mcServer->mAndroidClient.end(); ++iter)
		    {
		    	nResult = -1;

		    	int nFD = iter->first;
		    	JUZ_ANDROID_CLIENT *jzAndroid = iter->second;
		    	string listUser = jzAndroid->loginInfo.user;
		    	string listPass = jzAndroid->loginInfo.pass;

		    	if(sendUser == listUser) //账号相同
		    	{
		    		if(sendPass == listPass)//密码相同
		    		{
		    			if(nFD == sendUserID)
		    			{
		    				nResult = 4;//登录成功
		    				nLoginSuccessFD = nFD;
		    				jzAndroid->isLogin = true;
		    			}
		    			else
		    			{
		    				jzAndroid->isLogin = false;
		    				nResult = 3;//被挤下线
		    			}
		    		}
		    		else
		    		{
		    			jzAndroid->isLogin = false;
		    			nResult = 2;//登录失败,账号或密码错误
		    		}
		    	}
		    	if(nResult != -1)
		    	{
		    		if(nResult != 4)
		    		{
		    			delete iter->second;
		    			mcServer->mAndroidClient.erase(iter);
		    		}


		    		SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
		    				nFD, 0x01, 0x03, 0x00, 0x00, sizeof(nResult), (char*)&nResult);
		    		sendKey->setPublicEncryption();

		    		if(nResult == 3)
		    		{
		    			SendFinshPro se = [](SendSocketJuzEvent*ev,int ab){
		      				ClientQuitJuzEvent *clQuitEv = new ClientQuitJuzEvent(ev->getNfd(),1000);//被挤下线
		    		    				TaskJuzEvent *taskEv = new TaskJuzEvent();
		    		    				taskEv->setWhat(2);//发送事件
		    		    				taskEv->setArg1(clQuitEv);
		    		    				mainPlugin::getInstance()->sendEvent(taskEv);
		    			};
		    			sendKey->setSendFinshPro(se);
		    		}
		    		mainPlugin::getInstance()->sendEvent(sendKey);

		    		JuzLog::LogA(4,"返回登录通知码1111111111　fd:%d　结果:%d",nFD,nResult);
		    	}

		    }
		    mcServer->mAndroidClientLock.unLock();

		    //同步东西

		    if(nResult == 4)//4 == 登录成功
		    {
		    	char test[3] = "12";
				//发送
				SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
						nLoginSuccessFD, 0x02, 0x01,mcServer->getmNumPeople() , 0x00, sizeof(test), (char*)test);

				mainPlugin::getInstance()->sendEvent(sendKey);
		    }
		}
		else
		{
			nResult = 1; //目标服务器不存在
			SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
					sendUserID, 0x01, 0x03, 0x00, 0x00, sizeof(nResult), (char*)&nResult);
			sendKey->setPublicEncryption();
			mainPlugin::getInstance()->sendEvent(sendKey);

    		JuzLog::LogA(4,"返回登录通知码2222222222　fd:%d　结果:%d",sendUserID,nResult);
		}
	}
	else
	{
		nResult = 2;//登录失败,账号或密码错误
		SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
				sendUserID, 0x01, 0x03, 0x00, 0x00, sizeof(nResult), (char*)&nResult);
		sendKey->setPublicEncryption();
		mainPlugin::getInstance()->sendEvent(sendKey);

		JuzLog::LogA(4,"返回登录通知码3333333　fd:%d　结果:%d",sendUserID,nResult);
	}

	delete[] socketInfo->getData();
}
void mainPlugin::androidOnLogin(SocketInfoJuzEvent *socketInfo)
{
	//android 登录
	int nDataLen = socketInfo->getLen() - SOCKETHEAD;
	int nSocketFD = socketInfo->getNfd();
	JuzLoginInfoAndroid *juzLogin = (JuzLoginInfoAndroid*)socketInfo->getData();
	int nResult = -1;
	string serverUser = juzLogin->serverUser;

	JuzLog::LogA(4,"androidOnLogin　请求登录服务器账号:%s 用户:%s 密码:%s:",juzLogin->serverUser,juzLogin->user,juzLogin->pass);

	mMcServerLock.readLock();
	McServer *mcServer = NULL;
	auto it = mMcServer.find(serverUser);
	if(it != mMcServer.end())
	{
		mcServer = it->second;
	}
	mMcServerLock.unLock();

	if(mcServer != NULL) //服务器村存在
	{
		if(mcServer->getOnline())
		{
			bool isFindClient = false;

			JuzLog::LogStr("android 登录寻找自己");
			mcServer->mAndroidClientLock.readLock();
			auto AndroidFindit = mcServer->mAndroidClient.find(nSocketFD);
			if(AndroidFindit != mcServer->mAndroidClient.end())
			{
				//找到
				isFindClient = true;
			}
			mcServer->mAndroidClientLock.unLock();

			nResult = -1;

			STRUCT_AskUser ask;
			ask.ju = *juzLogin;
			ask.nfd = nSocketFD;

			mcServer->mAndroidClientLock.writeLock();
			if(isFindClient)
			{
				JuzLog::LogStr("android 登录找到自己");
				JUZ_ANDROID_CLIENT *juzClientData = AndroidFindit->second;
				juzClientData->loginInfo = *juzLogin;
			}
			else
			{
				JuzLog::LogStr("android 登录没找到自己插入");
				JUZ_ANDROID_CLIENT *jzNew = new JUZ_ANDROID_CLIENT;
				jzNew->isLogin = false;
				jzNew->loginInfo = *juzLogin;

				mcServer->mAndroidClient.insert(pair<int,JUZ_ANDROID_CLIENT*>(nSocketFD,jzNew));
			}

			mcServer->mAndroidClientLock.unLock();

			JuzLog::LogA(4,"androidOnLogin　登录发送信息到服务器:%s fd:%d",juzLogin->serverUser,mcServer->getRootFd());

			//发送消息  让mc服务器验证账号密码
			SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
					mcServer->getRootFd(), 0x01, 0x04, 0x00, 0x00, sizeof(STRUCT_AskUser), (char*)&ask);
			sendKey->setPublicEncryption();

			mainPlugin::getInstance()->sendEvent(sendKey);
		}
		else
		{
			nResult = 1;
		}

	}
	else
	{
		nResult = 1;//目标服务器不存在
	}

	if(nResult != -1)
	{
		JuzLog::LogA(4,"androidOnLogin　请求登录但服务器不存在:%d",socketInfo->getNfd());

		SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
				socketInfo->getNfd(), 0x01, 0x03, 0x00, 0x00, sizeof(nResult), (char*)&nResult);
		sendKey->setPublicEncryption();
		mainPlugin::getInstance()->sendEvent(sendKey);
	}

	delete[] socketInfo->getData();
}
void mainPlugin::mcOnLogin(SocketInfoJuzEvent *socketInfo)
{
	int nDataLen = socketInfo->getLen() - SOCKETHEAD;

	int nResult = 0;//0 = 账号不存在  1 = 账号已经上线(好像已经没用了)  nResult = 2密码错误　　＝　３登录成功
	//４　＝　被挤下线

	JuzLoginInfo *loginInfo = (JuzLoginInfo*)socketInfo->getData();

	McServer *mcServer = NULL;

	mMcServerIterator it;
	string strUser = loginInfo->user;
	string strPass = loginInfo->pass;

	JuzLog::LogA(4,"mc服务器登录:%s 密码:%s",loginInfo->user,loginInfo->pass);

	mMcServerLock.readLock();
	 it = mMcServer.find(strUser);
	 if (it != mMcServer.end())
	 {
		 mcServer = it->second;
	 }
	mMcServerLock.unLock();

	auto sendPro = [&](int nfd,int nState){

		SendSocketJuzEvent *sendKey = new SendSocketJuzEvent(
				nfd, 0x01, 0x02, 0x01, 0x00, sizeof(nState), (char*)&nState);
		sendKey->setPublicEncryption();
		//让发送线程去发送
		mainPlugin::getInstance()->sendEvent(sendKey);
	};

	if(mcServer != NULL)
	{
		//不在线 验证密码
		if(strPass == mcServer->mPass)
		{
			if(mcServer->getOnline())
			{
				int oldState = 4;//被挤下线
				sendPro(mcServer->getRootFd(),oldState);
				JuzLog::LogStr("挤掉服务端",4);
			}
			nResult = 3;//登录成功
			mcServer->setRootFd(socketInfo->getNfd());
		}
		else
		{
			nResult = 2; //密码错误
		}
	}


	JuzLog::LogA(4,"mc服务器登录完成:%s 密码:%s",loginInfo->user,loginInfo->pass);

	delete[] socketInfo->getData(); //删掉
	sendPro(socketInfo->getNfd(),nResult);
}

void mainPlugin::insertMcServer(string user,McServer* ser)
{
	mMcServerLock.writeLock();
	mMcServer.insert(pair<string,McServer*>(user,ser));
	mMcServerLock.unLock();
}

